package gameobj;

import java.awt.Graphics;
import java.awt.Rectangle;

import render.Model;
import render.SimpleModel;

/**
 * @说明
 * @author YOU友
 * @二作 Passerby
 * @所有元素的基类
 */
public abstract class GameObject {

	private int x;
	private int y;
	private int w;
	private int h;
	private Model model;
	
//	是否参与运算
	private boolean active = true;
//	是否存活（是否需要销毁）
	private boolean alive = true;
	
	public GameObject () {
//		由于draw函数必须要有model，故在此初始化一个空的model
		model = new SimpleModel();
	}
	
	public GameObject(int x,int y, int w,int h,Model model,boolean active) {
		this.x=x;
		this.y=y;
		this.w=w;
		this.h=h;
		if (model == null) {
//			如果为空则置为空的简单model，使render函数不至于不执行
			model = new SimpleModel();
		}
		this.model=model;
		this.active=active;
	}
//  碰撞检测矩形
	public Rectangle getRectangle() {//实时返回元素的碰撞矩形对象

		//System.out.println("场景中GameObject坐标: ("+x+","+y+","+w+","+h+")");
		return new Rectangle(x,y,w,h);
		
	}

	public GameObject create (String data)
	{
		return this;
	}
	
	public void render (Graphics g)
	{
		model.draw(g, x, y);
	}
	
	public abstract void ObjRun ();
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	
	public Model getModel() {
		return model;
	}
	public void setModel(Model model) {
		this.model = model;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	
	public boolean isAlive() {
		return alive;
	}
	
	public void setAlive(boolean alive) {
		this.alive = alive;
	}
	
	public int getW() {
		return w;
	}
	public void setW(int w) {
		this.w = w;
	}
	public int getH() {
		return h;
	}
	public void setH(int h) {
		this.h = h;
	}

}